import React, { Component } from 'react';
import {
    View,
    Text,
    ListView,
} from 'react-native';

import { Salarylist_style as styles } from '../../../../../styles';
import Salary_in from './salaryin'

const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => { r1 !== r2 } });//listView 数据判断方式
export default class Salary_list extends Component {
    // 初始化模拟数据
    constructor(props) {
        super(props);
        this.state = {
            dataSource: [
                { key: 's_x_10000', body: '12万以下', state: false },
                { key: 's_10000_25000', body: '12-30万', state: false },
                { key: 's_25000_50000', body: '30-60万', state: false },
                { key: 's_50000_100000', body: '60-120万', state: false },
                { key: 's_100000_x', body: '120万以上', state: false }
            ]
        };
    }

    render() {
        //创建listView数据源
        const dataSource = ds.cloneWithRows(this.state.dataSource);
        return (
            <View style={[styles.sal_all, { flex: 1 }]}>
                <Text style={styles.sal_toptext}>薪资条件</Text>
                <ListView
                    dataSource={dataSource}
                    renderRow={this.renderRow.bind(this)}
                    contentContainerStyle={styles.sal_list}
                    initialListSize={1000} />
            </View>
        );
    }

    renderRow(rowData) {
        return (
            <Salary_in
                change={this.change.bind(this)}
                _salary={this.props._salary.bind(this)}
                rowData={rowData}
            />
        )
    }

    change(a) {
        let list = this.state.dataSource;
        for (let i = 0; i < list.length; i++) {
            if (list[i].body == a) {
                list[i].state = true;
            } else if (list[i].body != a) {
                list[i].state = false;
            }
        }
        this.setState({ dataSource: list })
    }

}